<?php


namespace App\Listeners;

use App\Events\OrderPaySuccess;
use App\Events\OrderReceive;
use App\Models\Group;
use App\Models\Order;
use App\Services\NoticeService;

/**
 * Class OrderReceiveUpdateListener
 * @package App\Listeners
 */
class OrderReceiveUpdateListener
{
    /** @var Order */
    public $order;

    /**
     * Handle the event.
     *
     * @param  OrderPaySuccess $event
     * @return void
     * @throws \Throwable
     */
    public function handle(OrderReceive $event)
    {
        $this->order = $event->order;


        $this->doLegwork();
    }

    /**
     * 瓜瓜配送更新字段
     */
    private function doLegwork()
    {
        //通知第三方外卖平台订单状态
        $group = Group::whereAppId($this->order->uid)->first();
        info('通知送达');
        if($group){
            //通知接单成功
            NoticeService::send_order($this->order,2,$group->callback);
        }
    }
}
